<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Delete Resident</title>
	<link rel="stylesheet" href="jquery-ui-1.8.7.custom/development-bundle/themes/base/jquery.ui.all.css">
	<link rel="stylesheet" href="style.css">
	<script src="jquery-ui-1.8.7.custom/development-bundle/jquery-1.4.4.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/external/jquery.bgiframe-2.1.2.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.mouse.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.draggable.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.position.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.resizable.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.ui.dialog.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.effects.core.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.effects.blind.js"></script>
	<script src="jquery-ui-1.8.7.custom/development-bundle/ui/jquery.effects.explode.js"></script>
	<link rel="stylesheet" href="jquery-ui-1.8.7.custom/development-bundle/demos/demos.css">
	<script>
	function deleteResident(){
		<?php
		
			$studentnumber=$_POST["deletables"];
		echo "alert(\"".$studentnumber."\")";
			/*$con = mysql_connect("localhost","root","");

			if(!$con)
				{
					die('Could not connect: ' . mysql_error());
				}
	
			mysql_select_db("accidorm_database", $con);

			mysql_query("DELETE FROM resident WHERE studentnumber='".$studentnumber."'");

			mysql_close($con);*/
		?>
	}
	</script>
	<script>
	// increase the default animation speed to exaggerate the effect
	$.fx.speeds._default = 1000;
	$(function() {
		$( "#dialog" ).dialog({
			autoOpen: false,
			modal: true,
			hide: "explode",
			buttons: {
				"Delete": function() {
					deleteResident();
					$( this ).dialog( "close" );
					
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});
		$( "#dialog2" ).dialog({
			autoOpen: false,
			modal: true,
			hide: "explode",
		});
		$( "#opener" ).click(function() {
			if(document.adminform.deletables.value!="None"){
				$( "#dialog" ).dialog( "open" );
				return false;
			}else{
				$( "#dialog2" ).dialog( "open" );
				return false;
			}
		});
	});
	</script>
</head>
<body>

<div class="demo">

	<div id="header">
		<h1>ACCI DORM Management System</h1>
	</div>

	<div>
		<h3>Choose the resident you want to delete:<br/></h3>
		<?php
			$con = mysql_connect("localhost","root","");

			if(!$con)
				{
					die('Could not connect: ' . mysql_error());
				}
	
			mysql_select_db("accidorm_database", $con);

			$result = mysql_query("SELECT * FROM resident");

			if($row = mysql_fetch_array($result)){
				echo "<form name=\"adminform\" method=\"post\">";
				echo "<select name=\"deletables\">";
				echo "<option>None</option>";
				echo "<option>".$row['studentnumber']."</option>";
				while($row = mysql_fetch_array($result)){
					echo "<option>".$row['studentnumber']."</option>";
				}
				echo "</select>";
				echo "</form>";
			}else{
		?>
			No items to delete.
		<?php
			}mysql_close($con);
		?>
	</div>
	
	<div id="dialog" title="Confirm Delete?">
		Are you sure to delete the selected item?
	</div>
	<div id="dialog2" title="Confirm Delete?">
		Nothing to Delete
	</div>
	<br/>
	<button id="opener">Delete</button>

</div><!-- End demo -->
</body>
</html>
